home *** CD-ROM | disk | FTP | other *** search
- /* ---------------------------------------------------------------------------------------------
- Find_icon, code for constructing icon suites for files and folders
-
- by James W. Walker
- preferred e-mail: <mailto:jwwalker@kagi.com>
- alternate e-mail: <mailto:jwwalker@aol.com>, <jim@nisus-soft.com>
- web: <http://users.aol.com/jwwalker/>
-
- File: DTGetIconSuite.c
-
- Copyright ©1997 by James W. Walker
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours.
- If you're going to re-distribute the source, please make it clear
- that the code was descended from James W. Walker's code,
- but that you've made changes.
- ---------------------------------------------------------------------------------------------
- */
- #include <Errors.h>
- #include "MoreDesktopMgr.h"
- #include "cheap-exceptions.h"
- #include "DTGetIconSuite.h"
-
-
- typedef struct {
- OSType fileCreator;
- OSType fileType;
- short vRefNum;
- Boolean no_mask;
- } DTAddingData;
-
- static short ResIconToDTIcon( OSType iconType )
- {
- short DT_type;
-
- switch (iconType)
- {
- case large1BitMask:
- DT_type = kLargeIcon;
- break;
- case large4BitData:
- DT_type = kLarge4BitIcon;
- break;
- case large8BitData:
- DT_type = kLarge8BitIcon;
- break;
- case small1BitMask:
- DT_type = kSmallIcon;
- break;
- case small4BitData:
- DT_type = kSmall4BitIcon;
- break;
- case small8BitData:
- DT_type = kSmall8BitIcon;
- break;
- default:
- DT_type = 0;
- break;
- }
- return DT_type;
- }
-
- /*****************************************************************************/
-
- static pascal OSErr AddOneDTIcon(
- /* --> */ ResType theType,
- /* <-> */ Handle *theIcon,
- /* <-> */ DTAddingData *data )
- {
- OSErr error;
-
- error = DTGetIcon( NULL, data->vRefNum, ResIconToDTIcon( theType ),
- data->fileCreator, data->fileType, theIcon );
-
- if ( (error == noErr) && ( (theType == 'ICN#') || (theType == 'ics#') ) )
- {
- data->no_mask = false;
- }
-
- return error;
- }
-
- /*****************************************************************************/
-
- pascal OSErr DTGetIconSuite(
- /* --> */ short vRefNum,
- /* --> */ IconSelectorValue iconTypes,
- /* --> */ OSType fileCreator,
- /* --> */ OSType fileType,
- /* <-- */ Handle *iconSuite)
- {
- OSErr error;
- IconActionUPP add_DB_icon_UPP;
- DTAddingData adding_data;
-
- // DTGetIcon doesn't know about mini icons, and returns paramErr
- // if you ask for one. But I don't want that to cause our
- // suite construction to fail. So, just make sure that
- // DTGetIcon is never asked for mini icons.
- iconTypes &= ~kSelectorAllMiniData;
-
- error = NewIconSuite( iconSuite );
- if (error == noErr)
- {
- add_DB_icon_UPP = NewIconActionProc( AddOneDTIcon );
- require_action( add_DB_icon_UPP, NewIconActionProc, error = memFullErr );
- adding_data.no_mask = true;
- adding_data.fileCreator = fileCreator;
- adding_data.fileType = fileType;
- adding_data.vRefNum = vRefNum;
-
- error = ForEachIconDo( *iconSuite, iconTypes,
- add_DB_icon_UPP, &adding_data );
-
- DisposeRoutineDescriptor( add_DB_icon_UPP );
- NewIconActionProc:
- if ( (error == noErr) && adding_data.no_mask )
- {
- error = noMaskFoundErr;
- }
- }
-
- return error;
- }
-